#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>

struct ListNode
{
    int val;
    struct ListNode* next;
};

struct ListNode* partition(struct ListNode* pHead, int x)
{
    struct ListNode* Lguard, * Gguard, * Ltail, * Gtail, * tail = pHead, * Ltmp, * Gtmp;
    Lguard = (struct ListNode*)malloc(sizeof(struct ListNode));
    Gguard = (struct ListNode*)malloc(sizeof(struct ListNode));
    Gguard->next = Lguard->next = NULL;
    Ltmp = Lguard;
    Gtmp = Gguard;

    while (tail)
    {
        if (tail->val < x)
        {
            Lguard->next = tail;
            Lguard = Lguard->next;
            tail = tail->next;
        }
        else
        {
            Gguard->next = tail;
            Gguard = Gguard->next;
            tail = tail->next;
        }
    }

    Lguard->next = Gtmp->next;
    Gguard->next = NULL;

    return Ltmp->next;
}


int main()
{

	return 0;
}